#进行 重写JWT返回结果方法
from rest_framework.response import Response


def jwt_response_payload_handler(token,user,request):
    return{
        "id":user.id,
        "username":user.username,
        "token":token
    }



# 获取,保存用户自定义分页器
from rest_framework.pagination import PageNumberPagination

class PageNum(PageNumberPagination):
    page_size_query_param = "pagesize"

    max_page_size = 8

    # 重写分页返回结果方法
    def get_paginated_response(self, data):
        return Response({
            "counts":self.page.paginator.count,
            "lists":data,
            "page":self.page.number,
            "pages":self.page.paginator.num_pages,
            "pagesize":self.max_page_size
        })

    '''
     {
        "counts": "用户总量",
        "lists": [
            {
                "id": "用户id",
                "username": "用户名",
                "mobile": "手机号",
                "email": "邮箱"
            },
            ...
        ],
        "page": "页码",
        "pages": "总页数",
        "pagesize": "页容量"
      }
    '''